#include "ReservedMap.h"

#include "..\Util.h"

namespace BroodWar
{
	namespace Addon
	{
		BWSAL::ReservedMap* ConvertIReservedMap(IReservedMap^ map)
		{
			ReservedMap^ rm = DirectCast<ReservedMap^>(map);
			return ConvertReservedMap(rm);
		}
		
		BWSAL::ReservedMap* ConvertReservedMap(ReservedMap^ map)
		{
			if(map == nullptr)
				return NULL;
			return map->instance;
		}

		ReservedMap^ ConvertReservedMap(BWSAL::ReservedMap* map)
		{
			if(map == NULL)
				return nullptr;
			return gcnew ReservedMap(map);
		}

		ReservedMap::ReservedMap()
		{
			instance = BWSAL::ReservedMap::create();
		}

		ReservedMap::ReservedMap(BWSAL::ReservedMap* map)
		{
			instance = map;
		}
		
		ReservedMap::~ReservedMap()
		{
			BWSAL::ReservedMap::destroy();
		}
		
		ReservedMap::!ReservedMap()
		{
			BWSAL::ReservedMap::destroy();
		}
		
		ReservedMap^ ReservedMap::Instance::get()
		{
			if(s_instance == nullptr)
				s_instance = gcnew ReservedMap();
			return s_instance;
		}

		void ReservedMap::ReserveTiles(TilePosition^ position, Api::Enum::UnitType type, int width, int height)
		{
			instance->reserveTiles(ConvertTile(position), ConvertUnitType(type), width, height);
		}
		
		void ReservedMap::ReserveTiles(TilePosition^ position, Api::Enum::UnitType type, int width)
		{
			instance->reserveTiles(ConvertTile(position), ConvertUnitType(type), width);
		}
		
		void ReservedMap::ReserveTiles(TilePosition^ position, Api::Enum::UnitType type)
		{
			instance->reserveTiles(ConvertTile(position), ConvertUnitType(type));
		}
		
		void ReservedMap::FreeTiles(TilePosition^ position, int width, int height)
		{
			instance->freeTiles(ConvertTile(position), width, height);
		}
		
		void ReservedMap::FreeTiles(TilePosition^ position, int width)
		{
			instance->freeTiles(ConvertTile(position), width);
		}
		
		void ReservedMap::FreeTiles(TilePosition^ position)
		{
			instance->freeTiles(ConvertTile(position));
		}

		bool ReservedMap::IsReserved(int x, int y)
		{
			return instance->isReserved(x, y);
		}
		
		bool ReservedMap::IsReserved(TilePosition^ p)
		{
			return instance->isReserved(ConvertTile(p));
		}
		
		bool ReservedMap::CanBuildHere(Unit^ builder, TilePosition^ position, Api::Enum::UnitType type)
		{
			return instance->canBuildHere(ConvertUnit(builder), ConvertTile(position), ConvertUnitType(type));
		}
		
		Api::UnitType^ ReservedMap::GetReservedType(int x, int y)
		{
			return ConvertUnitType(instance->getReservedType(x, y));
		}
		
		Api::UnitType^ ReservedMap::GetReservedType(TilePosition^ p)
		{
			return ConvertUnitType(instance->getReservedType(ConvertTile(p)));
		}
	}
}
